package tree;

import lexer.Token;

public class TypingException extends Exception {
	
	/**
	 * Default Serial Number
	 */
	private static final long serialVersionUID = 1L;

	public TypingException(Token token, String msg) {
		super(token.toString() + msg);
	}

	public static TypingException expected(Tree where, Type expected, Type found) {
		return new TypingException(where.getToken(), String.format(" expected type %s but got %s", expected, found));
	}

	public static TypingException expected(Tree where, Type found, Type ... expected) {
		String exp = "";
		for (Type t : expected) {
			exp += (t.getDataType().name()+"  ");
		}
		return new TypingException(where.getToken(), String.format(" expected type %s but got %s", exp, found.getDataType().name()));
	}
	
	public static TypingException notEqual(Tree where, Tree t1, Tree t2, Type ty1, Type ty2) {
		return new TypingException(where.getToken(), String.format(" type %s of %s does not match with %s of %s", ty1.getDataType(), t1, ty2.getDataType(), t2));
	}
	
	public static TypingException illegalLiteral(Token token) {
		return new TypingException(token, String.format(" Illegal literal %s", token.getText()));
	}

}
